/*
 * @Description: 
 * @version: 
 * @Author: cy
 * @Date: 2021-12-31 17:02:21
 * @LastEditors: cy
 * @LastEditTime: 2022-04-28 09:21:10
 */
// LeeCode: 141
// 节点
function ListNode(val) {
    this.val = val;
    this.next = null;
}
var p1 = new ListNode(3);
var p2 = new ListNode(2);
var p3 = new ListNode(0);
var p4 = new ListNode(-4);
p1.next = p2;
p2.next = p3;
p3.next = p4;
p4.next = p1;


var hasCycle = function(head) {
    let p1 = head;
    let p2 = head;
    while(p1 && p2 && p2.next) {
        p1 = p1.next;
        p2 = p2.next.next;
        if (p1 === p2) {
            return true;
        }
    }
    return false;
}
var hasCycle = hasCycle(p1)
debugger